package po;

import java.util.ArrayList;


public class PayList {
	ArrayList<PayPOLineItem> list;
	double total = 0;

	public ArrayList<PayPOLineItem> getList() {
		return list;
	}

	public void setList(ArrayList<PayPOLineItem> list) {
		this.list = list;
	}

	public double getTotal() {
		return total;
	}

	public void setTotal(double total) {
		this.total = total;
	}
	
	public boolean add(PayPOLineItem item){
		total += item.getSum();
		return list.add(item);
	}

	public boolean delete(String accountId, double sum, String comment){
		PayPOLineItem item = find(accountId,sum,comment);
		return list.remove(item);
	}
	
	public boolean update(String accountId, double sum, String comment,String newAccountId, double newSum, String newComment){
		PayPOLineItem item = find(accountId,sum,comment);
		if(item != null){
			item.set(newAccountId, newSum, newComment);
			return true;
		}
		return false;
	}
	
	public PayPOLineItem find(String accountId, double sum, String comment){
		for(PayPOLineItem item : list){
			if(item.match(accountId, sum, comment)){
				return item;
			}
		}
		return null;
	}
}
